home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / pico / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-19  |  5.9 KB  |  220 lines

  1. /*
  2.  * Program:    Main stand-alone Pine Composer routines
  3.  *
  4.  * Modifier:    Michael Seibel
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: mikes@cac.washington.edu
  11.  *
  12.  * Date:    Nov 1989
  13.  * Last Edited:    9 September 1991
  14.  *
  15.  * Copyright 1991 by the University of Washington
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notice appears in all copies and that both the
  20.  * above copyright notice and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  32.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  *
  35.  * WEEMACS/PICO NOTES:
  36.  *
  37.  * 08 Jan 92 - removed PINE defines to simplify compiling
  38.  *
  39.  * 08 Apr 92 - removed PINE stub calls
  40.  *
  41.  */
  42.  
  43. #include        <stdio.h>
  44. #include    <setjmp.h>
  45. #include    "osdep.h"    /* operating system dependent includes */
  46. #include        "estruct.h"    /* global structures and defines */
  47. #include    "efunc.h"    /* function declarations and sans name table */
  48. #include    "edef.h"    /* global definitions */
  49. #include    "pico.h"    /* pine composer definitions */
  50.  
  51.  
  52. /*
  53.  * this isn't defined in the library, because it's a pine global
  54.  * which we use for GetKey's timeout
  55.  */
  56. int    timeout = 0;            /* global timeout value        */
  57.  
  58. /*
  59.  * function key mappings
  60.  */
  61. static int fkm[12][2] = {
  62.     { F1,  (CTRL|'G')},
  63.     { F2,  (CTRL|'X')},
  64.     { F3,  (CTRL|'O')},
  65.     { F4,  (CTRL|'J')},
  66.     { F5,  (CTRL|'R')},
  67.     { F6,  (CTRL|'W')},
  68.     { F7,  (CTRL|'Y')},
  69.     { F8,  (CTRL|'V')},
  70.     { F9,  (CTRL|'K')},
  71.     { F10, (CTRL|'U')},
  72.     { F11, (CTRL|'C')},
  73. #ifdef    SPELLER
  74.     { F12, (CTRL|'T')}
  75. #else
  76.     { F12, (CTRL|'D')}
  77. #endif
  78. };
  79.  
  80.  
  81. /*
  82.  * main standalone pico routine
  83.  */
  84. main(argc, argv)
  85. char    *argv[];
  86. {
  87.     register int    c;
  88.     register int    f;
  89.     register int    n;
  90.     register BUFFER *bp;
  91.     register int    carg;        /* current arg to scan         */
  92.     extern   int    pico_new_mail();
  93.     int         viewflag = FALSE;        /* are we starting in view mode?*/
  94.     int         starton = 0;        /* where's dot to begin with?    */
  95.     int         i;
  96.     char     bname[NBUFN];        /* buffer name of file to read    */
  97.     char    *clerr = NULL;        /* garbage on command line    */
  98.     
  99.     Pmaster = NULL;            /* turn OFF composer functionality */
  100.  
  101.     /*
  102.      * Read command line flags before initializing, otherwise, we never
  103.      * know to init for f_keys...
  104.      */
  105.     carg = 1;
  106.     while(carg < argc){
  107.     if(argv[carg][0] == '-'){
  108.         switch(argv[carg][1]){
  109.           case 'v':            /* -v for View File */
  110.           case 'V':
  111.         viewflag = !viewflag;
  112.         break;
  113.           case 'f':            /* -f for function key use */
  114.         gmode ^= MDFKEY;
  115.         break;
  116.           case 'n':            /* -n for new mail notification */
  117.         timeout = 180;
  118.         if(argv[carg][2] != '\0')
  119.           if((timeout = atoi(&argv[carg][2])) < 30)
  120.             timeout = 180;
  121.         break;
  122.           case 't':            /* special shutdown mode */
  123.         gmode ^= MDTOOL;
  124.         rebindfunc(wquit, quickexit);
  125.         break;
  126.           case 'z':            /* -z to suspend */
  127.         gmode ^= MDSSPD;
  128.         break;
  129.           case 'w':            /* -w turn off word wrap */
  130.         gmode ^= MDWRAP;
  131.         break;
  132.           default:            /* huh? */
  133.         clerr = argv[carg];
  134.         break;
  135.         }
  136.         carg++;
  137.     }
  138.     else if(argv[carg][0] == '+'){    /* leading '+' is special */
  139.         starton = atoi(&argv[carg][1]);
  140.         carg++;
  141.     }
  142.     else                /* pick up file name later... */
  143.       break;
  144.     }
  145.  
  146.     vtinit();                /* Displays.            */
  147.     strcpy(bname, "main");        /* default buffer name */
  148.     edinit(bname);            /* Buffers, windows.   */
  149.  
  150.     update();                /* let the user know we are here */
  151.  
  152. #if    TERMCAP
  153.     if(kpadseqs == NULL){        /* will arrow keys work ? */
  154.     (*term.t_putchar)('\007');
  155.     emlwrite("Warning: keypad keys may non-functional");
  156.     }
  157. #endif    /* TERMCAP */
  158.  
  159.     if(carg < argc){            /* Any file to edit? */
  160.  
  161.     makename(bname, argv[carg]);    /* set up a buffer for this file */
  162.  
  163.     bp = curbp;            /* read in first file */
  164.     makename(bname, argv[carg]);
  165.     strcpy(bp->b_bname, bname);
  166.     strcpy(bp->b_fname, argv[carg]);
  167.     if (readin(argv[carg], (viewflag==FALSE)) == ABORT) {
  168.         strcpy(bp->b_bname, "main");
  169.         strcpy(bp->b_fname, "");
  170.     }
  171.     bp->b_dotp = bp->b_linep;
  172.     bp->b_doto = 0;
  173.  
  174.     if (viewflag)            /* set the view mode */
  175.       bp->b_mode |= MDVIEW;
  176.     }
  177.  
  178.     /* setup to process commands */
  179.     lastflag = 0;            /* Fake last flags.     */
  180.     curbp->b_mode |= gmode;        /* and set default modes*/
  181.  
  182.     curwp->w_flag |= WFMODE;        /* and force an update    */
  183.  
  184.     if(timeout)
  185.       emlwrite("Checking for new mail every %D seconds", timeout);
  186.  
  187.     if(clerr){                /* post any errors on command line */
  188.     if(mpresf)            /* show earlier message though! */
  189.       sleep(2);
  190.     emlwrite("\007Unknown option: %s", clerr);
  191.     }
  192.  
  193.     forwline(0, starton);        /* move dot to specified line */
  194.  
  195.     while(1){
  196.  
  197.     update();            /* Fix up the screen    */
  198.  
  199.     c = GetKey();    
  200.  
  201.     if(timeout && (c == NODATA || time_to_check())){
  202.         if(pico_new_mail())
  203.           emlwrite("You may possibly have new mail.");
  204.  
  205.         if(c == NODATA)
  206.           continue;
  207.     }
  208.  
  209.     if(mpresf){            /* erase message line? */
  210.         if(mpresf++ > MESSDELAY)
  211.           mlerase();
  212.     }
  213.  
  214.     f = FALSE;
  215.     n = 1;
  216.  
  217.     execute(normal(c, fkm, 1), f, n);    /* Do it.               */
  218.     }
  219. }
  220.